<template>
	<el-dialog title="试卷信息" :visible.sync="dialogVisible" width="75%" v-dialogDrag>
		<span>当前试卷：{{paperTitle}}</span>
		<span>试卷题目总数：{{paperNum}}</span>
		<span>试卷题目现有数量：{{currentNum}}</span>
		<el-table :data="topicList" border style="width: 100%" v-loading="topicListLoading"
			element-loading-text="拼命加载中">
			<el-table-column label="编号" prop="topicId" header-align="center" align="center"
				:show-overflow-tooltip="true">
			</el-table-column>
			<el-table-column label="题目" prop="topicName" header-align="center" align="center"
				:show-overflow-tooltip="true">
			</el-table-column>
			</el-table-column>
			<el-table-column fixed="right" label="操作" header-align="center" align="center">
				<template slot-scope="scope">
					<el-button @click="deleteTopic(scope.row.topicId)" type="danger">删除</el-button>
				</template>
			</el-table-column>
		</el-table>
		<el-pagination @size-change="sizeChangeHandle1" @current-change="currentChangeHandle1"
			:current-page="pageIndex1" :page-size="pageSize1" :total="totalPage1" :pager-count="3"
			layout="total, prev, pager, next">
		</el-pagination>
		<span slot="footer" class="dialog-footer">
			<el-button @click="dialogVisible = false">关 闭</el-button>
		</span>
	</el-dialog>
</template>
<script>
	export default {
		data() {
			return {
				dataForm: {
					chapterName: '',
				},
				// 试卷题目开始
				topicList: [],
				pageIndex1: 1,
				pageSize1: 5,
				totalPage1: 0,
				dialogVisible: false,
				// 试卷题目结束
				dataListLoading: false,
				topicListLoading: false,
				show: false,
				paperId: 0,
				courseId: 0,
				paperNum: 0,
				paperTitle: '',
				currentNum: 0,
			}
		},
		activated() {

		},
		methods: {
			init(paperId, paperNum, paperTitle) {
				this.paperId = paperId;
				this.paperNum = paperNum;
				this.paperTitle = paperTitle;
				this.dialogVisible = true;
				this.getTopicListByTid();
			},
			/**
			 * @param {Object} id
			 * 加载试卷试题列表
			 */
			getTopicListByTid() {
				let _that = this;
				this.topicListLoading = true;
				this.$http({
					url: this.$http.adornUrl('/sys/paperInfo/getTopicListByTid'),
					method: 'get',
					params: this.$http.adornParams({
						'tid': this.paperId,
						'page': this.pageIndex1,
						'limit': this.pageSize1,
					})
				}).then(({
					data
				}) => {
					_that.topicList = []
					if (data && data.code === 0) {
						_that.topicList = data.data;
						_that.totalPage1 = data.count;
						_that.currentNum = data.count;
					} else {
						_that.topicList = [];
						_that.totalPage1 = 0;
					}
					this.topicListLoading = false;
				})
			},
			// 每页数
			sizeChangeHandle1(val) {
				this.pageSize1 = val
				this.pageIndex1 = 1
				this.getTopicListByTid()
			},
			// 当前页
			currentChangeHandle1(val) {
				this.pageIndex1 = val;
				this.getTopicListByTid()
			},
			/**
			 * @param {Object} id
			 * 从试卷中删除该题目
			 */
			deleteTopic(id) {
				this.$http({
					url: this.$http.adornUrl('/sys/paperInfo/delPaperInfo'),
					method: 'get',
					params: this.$http.adornParams({
						'tid': this.paperId,
						'id': id,
					})
				}).then(({
					data
				}) => {
					this.getTopicListByTid();
				})
			}
		}
	};
</script>
<style>
	.el-container {
		border: 1px solid #000000;
	}

	.el-aside {
		border-right: #000000 1px solid;
	}
</style>
